﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ShoppingCart.ascx.cs" Inherits="ShopOnline.Controls.ShoppingCart" %>

<%@ Register Assembly="ShopOnline" Namespace="ShopOnline.Controls" TagPrefix="cc" %>

<script type="text/javascript">
    function deleteProductByID<%=ClientID %>(id){
        var ok = confirm("Are you sure to delete this item?");
        if(!ok)
            return;
        var hidID = document.getElementById("<%= hidID.ClientID %>");
        hidID.value = id;
        var btn = document.getElementById("<%= btnDelete.ClientID %>");
        btn.click();
    }

    function deleteAllItems<%=ClientID %>(){
        var ok = confirm("Are you sure to delete all item(s)?");
        if(!ok)
            return;

        var hidID = document.getElementById("<%= hidID.ClientID %>");
        hidID.value = "-1";
        var btn = document.getElementById("<%= btnDelete.ClientID %>");
        btn.click();
    }

    function getTotalAmt<%=ClientID %>(){
        var hidTotalAmt  = document.getElementById("<%=hidTotalAmt.ClientID %>");
        return hidTotalAmt.value;
    }

    function showGrid(visible){
        var grid = document.getElementById("divGrid");
        if(visible)
            grid.style.display = "block";
        else
            grid.style.display = "none";
    }

    function updateQtyChange<%=ClientID %>(txt, id){
        var btn = document.getElementById("<%= btnChangeQty.ClientID %>");
        var hidID = document.getElementById("<%= hidID.ClientID %>");
        var hidQty = document.getElementById("<%= hidQty.ClientID %>");
        hidID.value = id;
        hidQty.value = txt.value;
        btn.click();
    }

    function openWindow(url) {
        wnd_gallery.navigateUrl = url;
        wnd_gallery.title = "Gallery";
        wnd_gallery.open();
    }

    function openWindowBC(url) {
        wnd_gallery.navigateUrl = url;
        wnd_gallery.title = "Business Card Viewer";
        wnd_gallery.open();
    }
</script>

<cc:WindowManager ID="windowManager" runat="server" />
<cc:Window ID="gallery" runat="server" URL="Default.aspx" Title="A" WindowWidth="660" WindowHeight="500" AllowResizing="false" AllowScrolling="false" />


<div id="divGrid" class="category-products" style='text-transform:none !important'>
    <cc:CustomGrid ShowFooter="true" Width="100%" AllowRowSelect="false" GridLines="None" OnItemDataBound="gridCart_OnItemDataBound" CssClass="clientGrid" ID="gridCart" runat="server" AutoGenerateColumns="false" DataKeyField="ID" OnNeedDataSource="gridCart_OnNeedDataSource" AllowPaging="false">
        <Columns>
            <cc:CustomTemplateField UniqueName="Name" HeaderText="Product">
                <ItemTemplate>
                    <a onclick='<%# ((int)Eval("Category") == 2 ? "openWindowBC(\"BCViewer.aspx?id=" + Eval("ProductID").ToString() : "openWindow(\"SlideShow.aspx?unique=1&id=" + Eval("ProductImage").ToString()) + "\"); return false;" %>' style='cursor:pointer;'>
                        <img title='Click to view full image.' style='border: 0px none white; vertical-align:middle' src='<%# Eval(ShopOnline.BasePage.PRODUCT_IMAGE) %>' height='24px' />
                    </a>
                    <a class='product-name' style='color:#ff339c' href='<%# (int)Eval("Category") == 2 ? string.Format("~/BusinessCard.aspx?id={0}", Eval("ProductID").ToString()) : string.Format("~/ProductDetails.aspx?{0}=", ShopOnline.BasePage.PRD) + string.Format("{0}_{1}", ShopOnline.Utilities.GetValidParam(Eval("ProductName").ToString()), Eval("ProductID").ToString())  %>' runat="server">
                        <asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
                    </a>
                </ItemTemplate>
            </cc:CustomTemplateField>
            <%--<cc:CustomBoundField UniqueName="Quantity" HeaderText="Quantity" DataField="Quantity" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:##,###}"></cc:CustomBoundField>--%>
            <cc:CustomTemplateField ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="50px" HeaderText="Quantity">
                <ItemTemplate>
                    <asp:Label ID="lblQuantity" runat="server" Text='<%# Eval("Quantity") %>'></asp:Label>
                    <asp:TextBox ID="txtQuantity" Height="16px" runat="server" Text='<%# Eval("Quantity") %>' onchange='<%# string.Format("updateQtyChange{1}(this, {0});", Eval("ID"), ClientID) %>' Width="90%"></asp:TextBox>

                    <asp:Panel ID="paypalPanel" Visible='<%# EnablePayPal %>' runat="server" >
                        <input type="hidden"  name='<%# "item_number_" + ((int)DataBinder.Eval(Container, "ItemIndex") + 1).ToString() %>' value='<%# Eval("BarCode") %>' />
                        <input type="hidden"  name='<%# "item_name_" + ((int)DataBinder.Eval(Container, "ItemIndex") + 1).ToString() %>' value='<%# Eval("ProductName") %>' />
                        <input type="hidden"  name='<%# "quantity_" + ((int)DataBinder.Eval(Container, "ItemIndex") + 1).ToString() %>' value='<%# Eval("Quantity") %>' />
                        <input type="hidden"  name='<%# "amount_" + ((int)DataBinder.Eval(Container, "ItemIndex") + 1).ToString() %>' value='<%# GetPrice((decimal)Eval("CustomerPrice"), (int)Eval("Quantity")) %>' />
                        <input type="hidden"  name='<%# "tax_" + ((int)DataBinder.Eval(Container, "ItemIndex") + 1).ToString() %>' value='0' />
                    </asp:Panel>
                </ItemTemplate>
            </cc:CustomTemplateField>
            
            <cc:CustomTemplateField UniqueName="CustomerPrice" HeaderText="Customer Price" ItemStyle-HorizontalAlign="Right">
                <ItemTemplate>
                   <%#  string.Format("{0:C}", Eval("CustomerPrice")) %>
                </ItemTemplate>
            </cc:CustomTemplateField>
            <cc:CustomBoundField UniqueName="GST" HeaderText="GST" DataField="GST" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:C}"></cc:CustomBoundField>
            <cc:CustomTemplateField UniqueName="TotalAmount" HeaderText="Total Amount" ItemStyle-HorizontalAlign="Right">
                <ItemTemplate>
                    <%#  string.Format("{0:C}", Eval("TotalAmount"))%>
                </ItemTemplate>
            </cc:CustomTemplateField>
            <cc:CustomTemplateField ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="20px" HeaderText="">
                <ItemTemplate>
                    <asp:LinkButton ID="btnDelete" runat="server" ToolTip="Delete" OnClientClick='<%# string.Format("deleteProductByID{1}({0}); return false;", Eval("ProductID"), ClientID) %>'>
                        <asp:Image ImageUrl="~/images/delete_icon.gif" runat="server" ID="imgDelete" />
                    </asp:LinkButton>
                </ItemTemplate>
                <HeaderTemplate>
                    <asp:LinkButton ID="btnDeleteAll" runat="server" ToolTip="Delete All" OnClientClick='<%# string.Format("deleteAllItems{0}(); return false;", ClientID) %>'>
                        <asp:Image ImageUrl="~/images/delete_icon.gif" runat="server" ID="imgDeleteAll" />
                    </asp:LinkButton>
                </HeaderTemplate>
            </cc:CustomTemplateField>
        </Columns>
    </cc:CustomGrid>
</div>

<asp:HiddenField ID="hidQty" runat="server" />
<asp:HiddenField ID="hidID" runat="server" />
<asp:HiddenField ID="hidTotalAmt" runat="server" />
<asp:Button style="display:none" ID="btnChangeQty" runat="server" OnClick="btnChangeQty_OnClick" />
<asp:Button style="display:none" ID="btnDelete" runat="server" OnClick="btnDelete_OnClick" />
<asp:HiddenField ID="hidSelectedID" runat="server" />
